<?php 

/*
 * author: li
 * createtim:2019/5/13 18:50
 * description:
 */
namespace app\admin\model;

use think\Model;
use think\Session;

class Student extends Model
{
    protected $autoWriteTimestamp = true;
    protected $createTime='create_time';
    protected $updateTime='update_time';

    public function getOldzxlogAttr($value, $data){
        $zxlog=db("zxlog")->where('res_id',$data['sid'])->order('z.create_time desc')
        ->alias('z')
        ->join('admin a', 'z.operator = a.id')
        ->field('z.*,a.username')
        ->select(); //咨询日志
        return $zxlog;
    }
    // public function getStatusTimeAttr($value, $data){
    //     if($value == 0 || empty($value)){
    //         $datetime = '';
    //     } elseif(date('Y-m-d H:i:s', $value)) {
    //         $datetime = date('Y-m-d H:i:s', $value);
    //     }
    //     return $datetime;
    // }
    // public function getContractRateAttr($value)
    // {
    //     $ContractRate = [
    //         0=>"确定签约",
    //         1=>"高",
    //         2=>"中",
    //         3=>"低",
    //         4=>"无"
    //     ];
    //     return $ContractRate[$value];
        
    // }
    // public function getStelAttr ($value) {
    //     $user = $this->user_info();
    //     if (in_array(41, $user['ra'])){
    //         return substr_replace($value, '****', 3, 4);
    //     }
    //     return $value;
        
    // }
    public function getZxrTelAttr ($value) {
        $user = $this->user_info();
        if (!in_array(41, $user['ra']) && !in_array(31, $user['ra'])){
            return substr_replace($value, '****', 3, 4);
        }
        return $value;
    }
    
    //判断用户是否存在
    public function user_info(){

        if(Session::has('user_info')){
            $rs = Session::get("user_info");
            $post = Role::where(array("r_id"=>$rs['roles_id']))->find();
            $rs['post'] = $post['r_name'];
            return $rs;
        }else{
           echo "<script>location.href='/Admin/Login/index';</script>";
           exit();
        }
    }

}


 ?>